<template>
    <div class="ossPlayer" :id="playerId" ></div>
</template>

<script>
    export default {
        name: "OSSPlayer",
        //向外暴露属性
        props:{
            playerId:{
                default:"oss-player"
            },
        },
        data:function () {
            return{
                //播放器实例
                ossPlayer:{},
            }
        },
        mounted() {
        },
        methods:{
            //暂停播放
            pause(){
                this.ossPlayer.pause();
            },
            //1.播放不同url
            playURL(url,coverPic){
                //如果播放器存在，则删除之前的播放器div
                if(this.ossPlayer){
                    this.ossPlayer=null;
                    //$("#J_prismPlayer").remove();
                    $("#"+this.playerId+'-player').remove();
                }

                //初始化播放器
                //$("#"+this.playerId).append(" <div  class=\"prism-player\" id=\"J_prismPlayer\"></div>");
                //变量id：初始化容器
                $("#"+this.playerId).append(" <div  class=\"prism-player\" id=\""+this.playerId+"-player\"></div>");
                this.ossPlayer=new Aliplayer({
                    /*id: 'J_prismPlayer',*/
                    //避免id重复
                    id:this.playerId+'-player',
                    width: '100%',
                    height:'350px',
                    autoplay: false,
                    source:url,
                    cover: coverPic,
                },function (player) {
                    /*let timer=setInterval(()=>{
                        let time=parseInt(player.getCurrentTime());
                        console.log("视频时长：",time);
                    },1000);*/
                })
            },
            //2.播放加密视频
            playVOD(vod){
                Loadings.show();
                this.$axios.get(process.env.VUE_APP_SERVER+'/source/admin/get-vod/'+vod)
                    .then((response)=>{
                        let resp=response.data;
                        if(resp.success){
                            //已有播放器，进行删除
                            if(this.ossPlayer){
                                this.ossPlayer=null;
                                $("#"+this.playerId+'-player').remove;
                            }
                            Loadings.hide();
                            //初始化播放器
                            $("#"+this.playerId).append(" <div  class=\"prism-player\" id=\""+this.playerId+"-player\"></div>");
                            this.ossPlayer=new Aliplayer({
                                id: this.playerId+'-player',
                                width: '100%',
                                height:'350px',
                                autoplay: false,
                                vid:vod,
                                playauth:resp.responseData,
                                cover:'https://cevent-source-cloud.oss-cn-beijing.aliyuncs.com/source/source_public/2021_05_03/2021_05_03_4ho0dubRTqiaUWCAaIYgqi_logo-500-300-4.jpg',
                                encryptType:1,//播放私有加密流时需要设置
                            },function (player) {
                                console.log("欢迎进入亚盟电商平台官网，ceevnt提供技术支持");
                            });
                        }else{
                            toast.warning('未获取到播放授权!!!');
                        }
                    });
            }
        }
    }
</script>

<style scoped>
    .ossPlayer{

    }
</style>